package demo1;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.border.EmptyBorder;

import view1_class.Face1;
import view1_class.Instruction;
import view1_class.MyBorrowRecord2;
import view1_class.MyBorrowRecord;
import view1_class.Search3;
import view1_class.Search4;
import view2_class.Face2;
import view2_class.Search;

public class Interface2 extends JFrame{
	JSplitPane jSplitPane;
	JPanel jp1,jp2;
	JPanel jframe;
	JButton search5;
	JButton search3;
	JButton borrowBook;
	JButton returnBook;
	JButton instruction;
	JPanel contentPane;
	private JLayeredPane layer;
	public Interface2(String number){
		Image icon = Toolkit.getDefaultToolkit().getImage("image/logo2.png");
		setIconImage(icon);//改变LOGO
		
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		contentPane.setBackground(Color.white);
		
		borrowBook=new JButton("借阅书籍");
		returnBook=new JButton("归还书籍");
		search5=new JButton("借书记录");
		search3=new JButton("管理员   ");
		instruction=new JButton("借阅规则");
		
		jp1=new JPanel();
		jp1.setBackground(Color.white);
		jp1.add(borrowBook);
		jp1.add(returnBook);
		jp1.add(search5);
		jp1.add(search3);
		jp1.add(instruction);
		
		
		Icon image1=new ImageIcon("image/借阅书籍.png");
		Icon image2=new ImageIcon("image/归还书籍.png");
		Icon image3=new ImageIcon("image/借书记录.png");
		Icon image4=new ImageIcon("image/管理员.png");
		Icon image5=new ImageIcon("image/借阅规则.png");
		
		search5.setFont(new Font("微软雅黑 Light", Font.BOLD, 20));
		search3.setFont(new Font("微软雅黑 Light", Font.BOLD, 20));
		borrowBook.setFont(new Font("微软雅黑 Light", Font.BOLD, 20));
		returnBook.setFont(new Font("微软雅黑 Light", Font.BOLD, 20));
		instruction.setFont(new Font("微软雅黑 Light", Font.BOLD, 20));//设置按钮字体及大小
		
		borrowBook.setIcon(image1);
		returnBook.setIcon(image2);
		search5.setIcon(image3);
		search3.setIcon(image4);
		instruction.setIcon(image5);

		borrowBook.setBackground(new Color(224,249,219));
		returnBook.setBackground(new Color(224,249,219));
		search5.setBackground(new Color(224,249,219));
		search3.setBackground(new Color(224,249,219));
		instruction.setBackground(new Color(224,249,219));//设置按钮背景为白色
		
		borrowBook.setBorderPainted(false);
		returnBook.setBorderPainted(false);
		search3.setBorderPainted(false);
		search5.setBorderPainted(false);
		instruction.setBorderPainted(false);//去除按钮边框
		
		jp2=new JPanel();
		jp2.setBackground(Color.white);
		
		jSplitPane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,jp1,jp2);
		//add(jSplitPane);
		jSplitPane.setDividerLocation(200); //分割线的位置  也就是初始位置
		jSplitPane.setOneTouchExpandable(false); //是否可展开或收起，在这里没用
		jSplitPane.setDividerSize(2);//设置分割线的宽度 像素为单位
		jSplitPane.setEnabled(false); //设置分割线不可拖动！！
		this.add(jSplitPane);  //加入到面板中就好
		setBounds(300,200,800,500);
		setVisible(true);
		jSplitPane.setDividerLocation(0.2);// 在1/2处进行拆分
		//按钮触发的事件
		jp1.setOpaque(false);
		jp2.setOpaque(false);
		
		Init(jSplitPane.getRightComponent(),new Face1());
		
        borrowBook.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				Init(jSplitPane.getRightComponent(),new Search4(Book.searchAllBook(),number));
				//用于显示图书列表及借书的界面
				
			}
		});
		returnBook.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				Init(jSplitPane.getRightComponent(),new MyBorrowRecord(Borrow.searchBookByStatus(number, "借书中"), number));
				;
				//用于显示在借图书列表及还书的界面
			}
		});
		search3.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				Init(jSplitPane.getRightComponent(),new Search3(Librarian.searchAllLibrarian()));
				//用于显示管理员列表的界面
			}
		});
		search5.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				Init(jSplitPane.getRightComponent(),new MyBorrowRecord2(Borrow.searchMyRecord(number)));
				
				//用于显示该登录学生的所有借书记录
			}
		});
		instruction.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				Init(jSplitPane.getRightComponent(),new Instruction());
				
				//用于所有用户的图书借阅规则
			}
		});
		setTitle("操作界面");
		setFont(new Font("微软雅黑 Light", Font.PLAIN, 20));
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		SetSwing.setCenter(this);// 使用内部类的静态方法
		setResizable(false);
		setVisible(true);
		setFocusable(true);
		validate();
		
		
	}
	public void Init(Component component,JPanel jp3){
		jSplitPane.remove(component);
		jSplitPane.add(jp3);
		jSplitPane.setDividerLocation(200); //分割线的位置  也就是初始位置
		jSplitPane.setOneTouchExpandable(false); //是否可展开或收起，在这里没用
		jSplitPane.setDividerSize(2);//设置分割线的宽度 像素为单位
		jSplitPane.setEnabled(false); //设置分割线不可拖动！！
		this.add(jSplitPane);  //加入到面板中就好
		setBounds(300,200,800,500);
		SetSwing.setCenter(this);
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		setVisible(true);
		jSplitPane.setDividerLocation(0.2);// 在1/2处进行拆分
		//按钮触发的事件
	}

}
